﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using DVSProject.Lib;
using DVSProject.Models;

namespace DVSProject.Controllers
{
    public class HandSoapDispenserRemarkController : Controller
    {
        //
        // GET: /HandSoapDispenserRemark/

        public ActionResult Index()
        {
            if (Session["User"] == null) { return RedirectToAction("LogOn", "Account"); }
            HandSoapDispenserRemarkRepo _HandSoapDispenserRemarkRepo = new HandSoapDispenserRemarkRepo();
            IEnumerable<HandSoapDispenserRemarkModels> _HandSoapDispenserRemarks = _HandSoapDispenserRemarkRepo.GetHandSoapDispenserRemark();
            return View(_HandSoapDispenserRemarks);
        }

        //
        // GET: /HandSoapDispenserRemark/Details/5

        public ActionResult Details(int id)
        {
            if (Session["User"] == null) { return RedirectToAction("LogOn", "Account"); }
            HandSoapDispenserRemarkRepo _HandSoapDispenserRemarkRepo = new HandSoapDispenserRemarkRepo();
            HandSoapDispenserRemarkModels HandSoapDispenserRemark = new HandSoapDispenserRemarkModels();
            HandSoapDispenserRemark = _HandSoapDispenserRemarkRepo.GetHandSoapDispenserRemarkById(id);
            return View(HandSoapDispenserRemark);
        }

        //
        // GET: /HandSoapDispenserRemark/Create

        public ActionResult Create()
        {
            if (Session["User"] == null) { return RedirectToAction("LogOn", "Account"); }
            HandSoapDispenserRemarkModels HandSoapDispenserRemark = new HandSoapDispenserRemarkModels();

            TitleHandSoapDispenserRepo _TitleHandSoapDispenserRepo = new TitleHandSoapDispenserRepo();
            IEnumerable<TitleHandSoapDispenserModels> _TitleHandSoapDispensers = _TitleHandSoapDispenserRepo.GetTitleHandSoapDispenser();
            int selectedId = 1;
            IEnumerable<SelectListItem> selectlist = from s in _TitleHandSoapDispensers
                                                     select new SelectListItem
                                                     {
                                                         Selected = (s.TitleHandSoapDispenserId == selectedId),
                                                         Text = s.TitleHandSoapDispenserName,
                                                         Value = s.TitleHandSoapDispenserId.ToString()
                                                     };

            HandSoapDispenserRemark.TitleSelect = selectlist;
            return View(HandSoapDispenserRemark);
        } 

        //
        // POST: /HandSoapDispenserRemark/Create

        [HttpPost]
        public ActionResult Create(FormCollection collection)
        {
            if (Session["User"] == null) { return RedirectToAction("LogOn", "Account"); }
            try
            {
                // TODO: Add insert logic here
                HandSoapDispenserRemarkRepo _HandSoapDispenserRemarkRepo = new HandSoapDispenserRemarkRepo();
                HandSoapDispenserRemarkModels HandSoapDispenserRemark = new HandSoapDispenserRemarkModels();
                HandSoapDispenserRemark.TitleHandSoapDispenserId = SF.GetInt32(collection["TitleHandSoapDispenserId"]);
                HandSoapDispenserRemark.HandSoapDispenserRemarkTh = collection["HandSoapDispenserRemarkTh"];
                HandSoapDispenserRemark.HandSoapDispenserRemarkEng = collection["HandSoapDispenserRemarkEng"];
                HandSoapDispenserRemark.CreateBy = (string)Session["User"];
                bool result = _HandSoapDispenserRemarkRepo.Create(HandSoapDispenserRemark);

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
        
        //
        // GET: /HandSoapDispenserRemark/Edit/5
 
        public ActionResult Edit(int id)
        {
            if (Session["User"] == null) { return RedirectToAction("LogOn", "Account"); }
            HandSoapDispenserRemarkRepo _HandSoapDispenserRemarkRepo = new HandSoapDispenserRemarkRepo();
            HandSoapDispenserRemarkModels HandSoapDispenserRemark = new HandSoapDispenserRemarkModels();

            HandSoapDispenserRemark = _HandSoapDispenserRemarkRepo.GetHandSoapDispenserRemarkById(id);

            TitleHandSoapDispenserRepo _TitleHandSoapDispenserRepo = new TitleHandSoapDispenserRepo();
            IEnumerable<TitleHandSoapDispenserModels> _TitleHandSoapDispensers = _TitleHandSoapDispenserRepo.GetTitleHandSoapDispenser();
            int selectedId = 1;
            IEnumerable<SelectListItem> selectlist = from s in _TitleHandSoapDispensers
                                                     select new SelectListItem
                                                     {
                                                         Selected = (s.TitleHandSoapDispenserId == selectedId),
                                                         Text = s.TitleHandSoapDispenserName,
                                                         Value = s.TitleHandSoapDispenserId.ToString()
                                                     };

            HandSoapDispenserRemark.TitleSelect = selectlist;
            return View(HandSoapDispenserRemark);
        }

        //
        // POST: /HandSoapDispenserRemark/Edit/5

        [HttpPost]
        public ActionResult Edit(int id, FormCollection collection)
        {
            if (Session["User"] == null) { return RedirectToAction("LogOn", "Account"); }
            try
            {
                // TODO: Add update logic here
                HandSoapDispenserRemarkRepo _HandSoapDispenserRemarkRepo = new HandSoapDispenserRemarkRepo();
                HandSoapDispenserRemarkModels HandSoapDispenserRemark = new HandSoapDispenserRemarkModels();

                HandSoapDispenserRemark.Id = id;
                HandSoapDispenserRemark.TitleHandSoapDispenserId = SF.GetInt32(collection["TitleHandSoapDispenserId"]);
                // _FeederRemark.FeederRemarkTh = collection["FeederRemarkTh"];
                HandSoapDispenserRemark.HandSoapDispenserRemarkTh = collection["HandSoapDispenserRemarkTh"];
                HandSoapDispenserRemark.HandSoapDispenserRemarkEng = collection["HandSoapDispenserRemarkEng"];
                HandSoapDispenserRemark.UpdateBy  = (string)Session["User"];
                bool result = _HandSoapDispenserRemarkRepo.Edit(HandSoapDispenserRemark);
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /HandSoapDispenserRemark/Delete/5
 
        public ActionResult Delete(int id)
        {
            if (Session["User"] == null) { return RedirectToAction("LogOn", "Account"); }
            HandSoapDispenserRemarkRepo _HandSoapDispenserRemarkRepo = new HandSoapDispenserRemarkRepo();
            HandSoapDispenserRemarkModels HandSoapDispenserRemark = new HandSoapDispenserRemarkModels();

            HandSoapDispenserRemark = _HandSoapDispenserRemarkRepo.GetHandSoapDispenserRemarkById(id);
            return View(HandSoapDispenserRemark);
        }

        //
        // POST: /HandSoapDispenserRemark/Delete/5

        [HttpPost]
        public ActionResult Delete(int id, FormCollection collection)
        {
            if (Session["User"] == null) { return RedirectToAction("LogOn", "Account"); }
            try
            {
                // TODO: Add delete logic here
                HandSoapDispenserRemarkRepo _HandSoapDispenserRemarkRepo = new HandSoapDispenserRemarkRepo();
                HandSoapDispenserRemarkModels HandSoapDispenserRemark = new HandSoapDispenserRemarkModels();
                HandSoapDispenserRemark.Id = id;
                HandSoapDispenserRemark.UpdateBy = (string)Session["User"];
                bool result = _HandSoapDispenserRemarkRepo.Delete(HandSoapDispenserRemark);
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
    }
}
